<extend name="layout/main" />

<block name="HEADER">
	<style type="text/css">
		.layui-tab-brief {
			position: relative;
		}
		.layui-tab-brief>.btnAdd {
			position: absolute;
			right: 100px;
			top: 5px;
			cursor: pointer;
			z-index: 1;
		}
		.layui-tab-brief>.btnDel {
			position: absolute;
			right: 20px;
			top: 5px;
			cursor: pointer;
			z-index: 1;
		}
		.layui-tab {
			height: 100%;
		}
		.layui-tab .layui-tab-content {
			overflow: auto;
			padding: 25px;
			height: calc(100% - 40px);
		}
		.dlList {
			margin-bottom: 22px;
			overflow: hidden;
		}
		.dlList dt {
			border-bottom: 1px solid #eaeaea;
			margin-bottom: 10px;
			padding-bottom: 5px;
			color: #000000;
			font-weight: bold;
		}
		.dlList dd {
			padding-left: 10px;
			float: left;
			margin-right: 50px;
			line-height: 24px;
			cursor: pointer;
			margin-bottom: 15px;
			width: 20%;
		}
		.dlList dd p {
			color: #219AFF;
			font-weight: bold;
		}
		.dlList dd span {
			color: #CCCCCC;
		}
		/*轮播图*/
		.fileUploadContainer {
			height: 100%;
		}
		.fileUpload-layui-carousel {
			height: calc(100% - 25px) !important;
		}
	</style>
</block>

<block name="CONTENT">
	<div class="layui-tab  layui-tab-brief">
		<div class="layui-tab-content" style="height: 100%;">
			<div class="layui-tab-item layui-show">
				<dl class="dlList">
					<dt>图片信息</dt>
					<dd data-data="{&quot;param_id&quot;:5,&quot;param_scope&quot;:&quot;业务参数&quot;,&quot;param_scope_sort&quot;:&quot;首页配置&quot;,&quot;param_type&quot;:&quot;slides&quot;,&quot;param_code&quot;:&quot;buess_index_banner&quot;,&quot;param_name&quot;:&quot;首页banner图&quot;,&quot;param_des&quot;:&quot;配置首页banner图片&quot;,&quot;page_url&quot;:null,&quot;page_size&quot;:null}">
						<p>首页banner图</p>
						<span>配置首页banner图片</span>
					</dd>
					<dd data-data="{&quot;param_id&quot;:25,&quot;param_scope&quot;:&quot;业务参数&quot;,&quot;param_scope_sort&quot;:&quot;首页配置&quot;,&quot;param_type&quot;:&quot;slides&quot;,&quot;param_code&quot;:&quot;buess_index_newimg&quot;,&quot;param_name&quot;:&quot;首页广播图&quot;,&quot;param_des&quot;:&quot;配置首页广播图&quot;,&quot;page_url&quot;:null,&quot;page_size&quot;:null}">
						<p>首页广播图</p>
						<span>配置首页广播图</span>
					</dd>
					
				</dl>
				
				<dl class="dlList">
					<dt>资讯信息</dt>
					<!--<dd data-data="" onclick="page.news('dynamic')">
						<p>最新动态</p>
						<span>配置首页最新动态</span>
					</dd>
					<dd data-data="" onclick="page.news('auditorium')">
						<p>健康大讲堂</p>
						<span>配置首页健康大讲堂信息</span>
					</dd>-->
					<dd data-data="" onclick="page.news('certificate')">
						<p>资质证书</p>
						<span>配置首页资质证书信息</span>
					</dd>
					<dd data-data="" onclick="page.news('about')">
						<p>关于我们</p>
						<span>配置关于我们信息</span>
					</dd>
				</dl>
				<!--<dl class="dlList">
					<dt>最新动态</dt>
					<dd data-data="" onclick="page.news('dynamic')">
						<p>首页展示</p>
						<span>配置首页最新动态的展示</span>
					</dd>
					<dd data-data="" onclick="page.news('dynamic',2)">
						<p>最新动态内容</p>
						<span>配置最新动态的内容信息</span>
					</dd>
				</dl>-->
			</div>
		</div>
	</div>

	<!--下拉新增-->
	<script id="tpl-selectType" type="text/html">
		<form class="layui-form J-selectType">
			<input type="hidden" name="id" value="{{id}}">
			<input type="hidden" name="param_code" value="{{param_code}}">
			<input type="hidden" name="param_scope" value="{{param_scope}}">
			<input type="hidden" name="param_value" value="{{param_value}}">
			<table class="xw-table">
				<tr> <th width="80"></th> <th></th> </tr>
				<tr>
					<td class="f-orage">名称</td>
					<td><input type="text" class="layui-input" name="param_text" value="{{param_text}}" datatype="*"></td>
				</tr>
			</table>
		</form>
	</script>

</block>

<block name="FOOTER">
	<script type="text/javascript">
		var page = (function(ns) {

			var selectGrid = null;

			//页面初始化
			ns.init = function() {
				$(".dlList dd").click(function() {
					ns.onClickParam($(this).data("data"));
				});
			}
			
			//资讯
			ns.news = function(type,mode){
				if(type  == 'auditorium'){
					var filter={
			            url:"modules/news/list",
			            oid:"",
			            mode:1,
			            type:type
			        }
					$.openIframe(filter, "资讯编辑",['830px', '90%']);
				}else{
					$.ajaxs('/admin/v1/news/getNew',{type:type}).then(function(res){
						var filter={
				            url:"modules/news/news",oid:"",
				            mode:1,type:type
				        }
						if(res.data){
							filter.oid = res.data;
							filter.mode = 2;
						}
						$.openIframe(filter, "资讯编辑",['830px', '90%']);
					});
				}
			}
			
			//点击参数
			ns.onClickParam = function(data) {
				switch(data.param_type) {
					case "radio":
						ns.radio(data, 3);
						break;
					case "text":
						ns.textOrTextarea(data, 3);
						break;
					case "textarea":
						ns.textOrTextarea(data, 2);
						break;
					case "number":
						ns.textOrTextarea(data, 4);
						break;
					case "select":
						ns.select(data);
						break;
					case "slides":
						ns.slides(data);
						break;
					case "custom":
						ns.custom(data);
						break;
				}
				
				
				
			}

			//单选类型
			ns.radio = function(data) {
				$.ajaxs("/admin/soft/param/getTextParamValue", data).then(function(res) {
					function successFn(index, layero) {
						if(res.data == '1') {
							layero.find("input[value='1']").prop("checked", true);
						}
						layui.form.render();
						layero.find('.layui-form-radio').eq(0).css("margin-right", "20px");
					}

					function yesFn(index, layero) {
						data.param_value = layero.find("input:checked").val();
						$.ajaxs("/admin/soft/param/saveTextParamValue", data, function() {
							$.toast(1, "保存成功！");
							layer.close(index);
						});
					}
					var html = '<div class="layui-form" style="text-align: center;line-height: 45px;"><input  type="radio" lay-skin="primary" name="state" title="否" value="0" checked><input type="radio" lay-skin="primary" data-opera="=" name="state" title="是" value="1" ></div>';
					$.openModalDialog(html, data.param_name, successFn, yesFn, ['250px', '150px']);
				});
			}

			// textarea类型
			ns.textOrTextarea = function(data, mode) {
				$.ajaxs("/admin/soft/param/getTextParamValue", data).then(function(res) {
					layer.prompt({
						title: data.param_name,
						formType: mode || 2,
						offset: '20%',
						value: res.data,
						yes: function(index, layero) {
							var value = layero.find(".layui-layer-input").val();
							if(mode == 4 && !Number(value) && value !== "0") {
								$.toast(0, "请输入数字类型！");
								return false;
							}
							data.param_value = value;
							$.ajaxs("/admin/soft/param/saveTextParamValue", data, function() {
								$.toast(1, "保存成功！");
								layer.close(index);
							});
						}
					});
				});
			}

			//下拉
			ns.select = function(data) {
				ns.selectData = data;

				function successFn(index, oLayer) {
					$(oLayer).find('.layui-layer-content').css("padding", '3px');
					var filter = [{
						"field": "param_scope",
						"opera": "=",
						"value": data.param_scope
					}];
					filter.push({
						"field": "param_code",
						"opera": "=",
						"value": data.param_code
					})
					selectGrid = layui.grid.render("selectGrid"); //参2非必填，默认当前config.xml
					selectGrid.load(filter);
				}

				function yesFn(index) {
					layer.close(index);
				}
				var html = '<div id="selectGrid" padding="0" height="100%"></div>';
				$.openModalDialog(html, data.param_name, successFn, yesFn, ['500px', '450px']);
			}

			//下拉编辑 type:1 = 新增， type:2 = 编辑， type:3 = 删除，
			ns.selectEdit = function(type) {
				if(type == 3) {
					selectGrid.deleteSelectRow();
					return false;
				}
				var selectedRow = selectGrid.getSelectedRows()[0];

				function successFn(index, oLayer) {
					$(oLayer).find("input[name='param_text']").bind("input propertychange", function() {
						$(oLayer).find("input[name='param_value']").val($(this).val());
					});
				}

				function yesFn(index) {
					var data = $(".J-selectType").serializeJson();
					$(".J-selectType").validformIn(function(data) {
						$.ajaxs("/admin/soft/param/saveParams", data, function(res) {
							$.toast(1, res.msg);
							selectGrid.load();
						});
						layer.close(index);
					});
				}
				ns.selectData.id = 0;
				var html = template("tpl-selectType", type == 1 ? ns.selectData : selectedRow);
				$.openModalDialog(html, type == 1 ? "新增" : '编辑', successFn, yesFn, ["320px", "200px"]);
			}

			//下拉移动  type: 1 = 上移 ,  type: 2 = 下移
			ns.move = function(type) {
				var grids = selectGrid;
				var rows = grids.getRows();
				var selectedRow = grids.getSelectedRows();
				if(!selectedRow[0]) {
					$.toast(0, "请先选择数据！");
					return;
				}
				if(selectedRow.length > 1) {
					$.toast(0, "只能选择一条数据！");
					return;
				}
				var coverId = -1;
				rows.forEach(function(h, index) {
					if(selectedRow[0].id == h.id) {
						if(type == 1) {
							if(rows[index - 1]) {
								coverId = rows[index - 1].id;
							}
						} else {
							if(rows[index + 1]) {
								coverId = rows[index + 1].id;
							}
						}
					}
				});
				var param = {
					moveId: selectedRow[0].id,
					coverId: coverId
				}
				$.ajaxs("/admin/soft/Param/sortMove", param, function(res) {
					grids.load()
				});
			}

			//幻灯片类型
			ns.slides = function(data) {
				function successFn() {
					layui.uploads.init({
						id: "upload",
						fkGuid: '00000000-0000-0000-0000-000000000000',
						ywName: "参数设置",
						fkType: data.param_code,
						multiple: true,
						mode: 1,
						actionCode: 0,
						showSwiper: true, //显示轮播图
						accept: 'images' //允许上传的文件,images,file,video（视频）、audio（音频）
					});
				}

				function yesFn(index) {
					layer.close(index)
				}
				var html = '<div id="upload"></div>';
				$.openModalDialog(html, data.param_name, successFn, yesFn, ['600px', '450px'], {
					btn: ["关闭"],
					offset: "35px"
				});
			}

			//自定义类型
			ns.custom = function(data) {
				if(!data.page_url) {
					$.toast(0, "页面路由不能为空！");
					return false;
				}
				data.url = data.page_url;
				data.mode = 1;
				$.openIframe(data, data.param_name, String(data.page_size).split(',') || ['520px', '450px']);
			}

			return ns;
		}({}));

		$(function() {
			page.init();
		});
	</script>
</block>